import { RecursiveCharacterTextSplitter } from 'langchain/text_splitter';
import { config } from '../config/config';
import { readFile } from 'fs/promises';

export class TextProcessor {
  private textSplitter: RecursiveCharacterTextSplitter;

  constructor() {
    this.textSplitter = new RecursiveCharacterTextSplitter({
      chunkSize: config.textSplitter.chunkSize,
      chunkOverlap: config.textSplitter.chunkOverlap
    });
  }

  async splitText(text: string) {
    return await this.textSplitter.splitText(text);
  }

  async processFile(filePath: string) {
    try {
      const text = await readFile(filePath, 'utf-8');
      return await this.splitText(text);
    } catch (error) {
      console.error('Error processing file:', error);
      throw error;
    }
  }
}
